package org.yh.moodpraise.rabbitmq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.yh.moodpraise.service.MoodService;

/**
 * @Author: yh
 * @Date: 2020/6/22
 * @Description:
 */

@Component
public class MQReceiver {
    private static final Logger log = LoggerFactory.getLogger(MQReceiver.class);
    @Autowired
    MoodService moodService;

    @RabbitListener(queues = MQConfiguration.QUEUENAME)
    public void receive(String msg){
        String[] strs = msg.split(":");
        Integer moodId=Integer.valueOf(strs[0]);
        Integer praiseIncrement=Integer.valueOf(strs[1]);
        log.info(">>> id为"+moodId+"的说说增加点赞数: "+praiseIncrement);
        //更新数据库点赞数
        moodService.updatePraiseIncrement(moodId,praiseIncrement);
    }
}
